package com.laowang.project.system.controller;

import java.util.Date;
import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import io.swagger.models.auth.In;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyCyhMerchantShare;
import com.laowang.project.system.service.MyCyhMerchantShareService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 商家分享入驻关联Controller
 * @author laowang
 * @date 2023-08-25
 */
@Api(tags = "商家分享入驻关联接口")
@RestController
@RequestMapping("/merchantShare")
public class MyCyhMerchantShareController extends BaseController {
    @Autowired
    private MyCyhMerchantShareService myCyhMerchantShareService;

    /**
     * 查询商家分享入驻关联列表
     */
    @ApiOperation(value = "查询商家分享入驻关联列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:merchantShare:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyCyhMerchantShare myCyhMerchantShare) {
        startPage();
        List<MyCyhMerchantShare> list = myCyhMerchantShareService.selectMyCyhMerchantShareList(myCyhMerchantShare);
        return getDataTable(list);
    }

    @ApiOperation(value = "小程序端 添加商家分享关系",notes = "")
    @GetMapping("/web/share")
    public AjaxResult webshare(Integer userId, Integer shareId) {
        if (userId == null || shareId == null){
            return AjaxResult.error("分享者为空或被分享者为空");
        }
        MyCyhMerchantShare myCyhMerchantShare = new MyCyhMerchantShare();
        myCyhMerchantShare.setUserId(userId);
        myCyhMerchantShare.setShareId(shareId);
        myCyhMerchantShare.setCreated(new Date());
        myCyhMerchantShareService.insertMyCyhMerchantShare(myCyhMerchantShare);
        return AjaxResult.success("操作成功");
    }

    /**
     * 导出商家分享入驻关联列表
     */
    @ApiOperation(value = "导出商家分享入驻关联列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:merchantShare:export')")
    //@Log(title = "商家分享入驻关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyCyhMerchantShare myCyhMerchantShare) {
        List<MyCyhMerchantShare> list = myCyhMerchantShareService.selectMyCyhMerchantShareList(myCyhMerchantShare);
        ExcelUtil<MyCyhMerchantShare> util = new ExcelUtil<MyCyhMerchantShare>(MyCyhMerchantShare.class);
        return util.exportExcel(list, "merchantShare");
    }

    /**
     * 获取商家分享入驻关联详细信息
     */
    @ApiOperation(value = "获取商家分享入驻关联详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:merchantShare:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myCyhMerchantShareService.selectMyCyhMerchantShareById(id));
    }

    /**
     * 新增商家分享入驻关联
     */
    @ApiOperation(value = "新增商家分享入驻关联",notes = "")
    @PreAuthorize("@ss.hasPermi('my:merchantShare:add')")
    //@Log(title = "商家分享入驻关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyCyhMerchantShare myCyhMerchantShare) {
        return toAjax(myCyhMerchantShareService.insertMyCyhMerchantShare(myCyhMerchantShare));
    }

    /**
     * 修改商家分享入驻关联
     */
    @ApiOperation(value = "修改商家分享入驻关联",notes = "")
    @PreAuthorize("@ss.hasPermi('my:merchantShare:edit')")
    //@Log(title = "商家分享入驻关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyCyhMerchantShare myCyhMerchantShare) {
        return toAjax(myCyhMerchantShareService.updateMyCyhMerchantShare(myCyhMerchantShare));
    }

    /**
     * 删除商家分享入驻关联
     */
    @ApiOperation(value = "删除商家分享入驻关联",notes = "")
    @PreAuthorize("@ss.hasPermi('my:merchantShare:remove')")
    //@Log(title = "商家分享入驻关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myCyhMerchantShareService.deleteMyCyhMerchantShareByIds(ids));
    }
}
